package com.zb.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjWorkSet;
import com.zb.mapper.ZjWorkSetMapper;
import com.zb.service.WorkLevelDefaultDataVoService;
import com.zb.service.ZjWorkSetService;
import com.zb.vo.WorkSetVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * <p>
 * 工单设置表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-07-25
 */
@Service
public class ZjWorkSetServiceImpl extends ServiceImpl<ZjWorkSetMapper, ZjWorkSet> implements ZjWorkSetService {
    @Resource
    private WorkLevelDefaultDataVoService workLevelDefaultDataVoService;

    // 初始化 或 恢复初始化工单设置
    @Override
    public void initOrRestoreDefaultWorkSet(Long custAccId) {
        ZjWorkSet workSet = new ZjWorkSet();
        workSet.setId(custAccId);
        workSet.setEnableRepeatOrder(false);
        workSet.setRepeatByMobile(false);
        workSet.setRepeatByService(false);
        workSet.setEnableRepeatOrderTip(true);
        workSet.setRepeatByMobileTip(true);
        workSet.setRepeatByServiceTip(true);
        workSet.setEnableProName(false);
        workSet.setEnableProModel(false);
        workSet.setEnableProCode(false);
        workSet.setEnableUserAccount(false);
        workSet.setEnableUserName(true);
        workSet.setEnableUserPhone(true);
        workSet.setEnableUserAddress(false);
        workSet.setFinishUpdate(false);
        workSet.setOpenRepairAuth(false);
        workSet.setCarryRegistInfo(true);
        workSet.setShowRelationSpare(false);
        this.saveOrUpdate(workSet);
    }

    // 初始化默认值
    @Override
    public void initDefaultValue(Long custAccId) {
        initOrRestoreDefaultWorkSet(custAccId);
        workLevelDefaultDataVoService.saveWorkDefaultLevel(custAccId);
    }

    // 获取工单设置
    @Override
    public WorkSetVo getWorkSet(Long custAccId) {
        ZjWorkSet workSet = this.getById(custAccId);
        return WorkSetVo.beanToVo(workSet);
    }

    // 保存工单设置
    @Override
    public void saveWorkSet(WorkSetVo workSetVo) {
        ZjWorkSet workSet = WorkSetVo.voToBean(workSetVo);
        this.updateById(workSet);
    }

    // 查询工单设置是否仅查询关联商品的配件
    @Override
    public boolean isShowRelationSpare(Long custAccId) {
        ZjWorkSet workSet = this.getById(custAccId);
        return null != workSet && workSet.getShowRelationSpare();
    }

}
